/**
 * represent patient type user
 *
 */

package source;

import java.util.List;
import java.util.Map;

import activejdbc.Model;

public class Patient extends Model {
	
	private String name;
	private String email;
	private String address;
	private String phone;
	private String gender; // Male or Female
	private String pharmacy;
	private String insurance;
	
	/* Get allergies by
	 * this.getAll(Allergy.class);
	 */
	
	public Patient() {
		super();
	}
	
	public Patient(Map<String, String> values) {
		this.fromMap(values);
	}
	
	
	/**
	 * request appointment with parameters patient, time, doctor
	 * @param values key-map, any values passed in, match them and fill in
	 */
	public void requestAppointment(Map<String, String> values) {
		Appointment app = new Appointment(values);
		app.set("patient_id", this.getLong("id"));
		app.saveIt();
	}
	
	// need to figure out association stuff
	/**
	 * find appointment by date which is associated with the patient
	 */
	public List<Appointment> getAppointments() {
		List<Appointment> app = this.getAll(Appointment.class);
		return app;
	}
	
	/**
	 *
	 * @return list of TreatmentRecord associated with the patient
	 */
	public List<TreatmentRecord> viewHistory() {
		List<TreatmentRecord> hist = this.getAll(TreatmentRecord.class);
		return hist;
	}
	
	public void addAllergy(String allergy) {
		Allergy a = new Allergy(allergy);
		a.set("patient_id", this.get("id"));
		a.saveIt();
	}
	
	public List<Allergy> getAllergies() {
		return this.getAll(Allergy.class);
	}
}
